package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.config.Config;
import com.example.a14110100409.yuejiandemo.javabean.Competion;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/11/9 0009.
 */

public class ComAdapter  extends RecyclerView.Adapter{
    private List<Competion> list;
    private Context context;
    private Competion competion;
    public  ComAdapter(Context context,List<Competion> list)
    {
        this.list=list;
        this.context=context;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_of_competion,viewGroup,false);
        ComViewHolder viewHolder=new ComViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        ComViewHolder viewHolder1=(ComViewHolder) viewHolder;
        competion=list.get(i);
        if (competion.getThumb()!=null||competion.getThumb()!="")
        {
            Picasso.with(context).load(Config.PIC_URL+competion.getThumb()).into(((ComViewHolder) viewHolder).pic);
        }
        else{
            viewHolder1.pic.setImageResource(R.drawable.dog);
        }
        viewHolder1.name.setText(competion.getName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class ComViewHolder extends RecyclerView.ViewHolder{
        ImageView pic;
        TextView name;
        public ComViewHolder(View itemView) {
            super(itemView);
            pic=(ImageView)itemView.findViewById(R.id.com_pic);
            name=(TextView)itemView.findViewById(R.id.com_name);
        }
    }
}
